package com.mark.springsecurity.service.impl;

import com.mark.springsecurity.domain.SysRole;
import com.mark.springsecurity.repository.SysRoleRepository;
import com.mark.springsecurity.service.ExcelService;
import com.mark.springsecurity.utils.ExcelHelper;
import org.springframework.stereotype.Service;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.List;

@Service
public class ExcelServiceImpl implements ExcelService {

    private final SysRoleRepository sysRoleRepository;

    public ExcelServiceImpl(SysRoleRepository sysRoleRepository) {
        this.sysRoleRepository = sysRoleRepository;
    }

    @Override
    public InputStream load() {
        List<SysRole> sysRoles = sysRoleRepository.findAll();
        ByteArrayInputStream in = ExcelHelper.tutorialsToExcel(sysRoles);
        return in;
    }
}
